package logic

import (
	"context"
	"time"
	"go-zero-service/service/user/api/internal/svc"
	"go-zero-service/service/user/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RedisLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRedisLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RedisLogic {
	return &RedisLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RedisLogic) Redis(req *types.RedisTestReq) (resp *types.RedisTestReply, err error) {
	// todo: add your logic here and delete this line
	l.svcCtx.DefaultRedis.Set("defaultkey"+string(req.Id), req.Value, 60 * time.Second)
	l.svcCtx.OrderRedis.Set("orderkey"+string(req.Id), req.Value, 60 * time.Second)

	value,err := l.svcCtx.DefaultRedis.Get("defaultkey"+string(req.Id)).Result()

	return &types.RedisTestReply{
		Id:       req.Id,
		Value:    value,
	}, err
}
